package com.jy.appmarket.network.engine.cachestrategy;

import java.io.File;
import java.util.Calendar;

import com.jy.appmarket.utils.StorageConfig;

/**
 * 类说明：
 * 
 * @author Baker.li
 * @date 2014年8月27日
 * @version 1.0
 */

public class WidgetCacheStrategy extends CacheStrategy {
	private String mFileName;

	public WidgetCacheStrategy(String fileName) {
		super(true);
		mFileName = fileName;
	}

	@Override
	public File getCacheFile() {
		return new File(StorageConfig.CACHE_DIR, mFileName);
	}

	public File getBakCacheFile() {
		return new File(StorageConfig.CACHE_DIR, mFileName + ".cache");
	}

	public boolean isNeedToDoNetWork() {
		int cYear, cMonth, cDate;
		Calendar calendar = Calendar.getInstance();
		cYear = calendar.get(Calendar.YEAR);
		cMonth = calendar.get(Calendar.MONDAY);
		cDate = calendar.get(Calendar.DATE);

		File file = getCacheFile();
		calendar.setTimeInMillis(file.lastModified());
		int fYear, fMonth, fDate;
		fYear = calendar.get(Calendar.YEAR);
		fMonth = calendar.get(Calendar.MONDAY);
		fDate = calendar.get(Calendar.DATE);

        return cYear != fYear || cMonth != fMonth || cDate != fDate;
	}
}
